<template>
    <view class="user-info flex px-[40rpx] justify-between py-[0rpx]">
        <!-- <view
            v-if="isLogin"
            class="flex items-center"
            @click="navigateTo('/pages/user_data/user_data')"
        > -->
        <view
            v-if="isLogin"
            class="flex items-center"
        >
            <u-avatar :src="user.avatar" :size="120"></u-avatar>
            <view class="u-main-color ml-[20rpx]">
                <view class="text-2xl">{{ user.nickname }}</view>
                <view class="text-xs mt-[18rpx] color-new-primary" @click.stop="copy(user.account)">
                    账号：{{ user.account }}
                </view>
            </view>
        </view>
        <navigator v-else class="flex items-center" hover-class="none" url="/pages/login/login">
            <u-avatar src="/static/images/user/default_avatar.png" :size="120"></u-avatar>
            <view class="u-main-color text-3xl ml-[20rpx]">未登录</view>
        </navigator>
		<view class="user-btn">
			<navigator v-if="isLogin" hover-class="none" url="/pages/user_set/user_set">
				<u-icon name="setting" color="#333333" :size="38"></u-icon>
			</navigator>
			<view class="pl-[30rpx]" v-if="isLogin" @click="logoutHandle()">
				<u-icon name="reload" color="#333333" :size="38"></u-icon>
			</view>
			<!-- <navigator class="pl-[30rpx]" v-if="isLogin" hover-class="none" url="/pages/user_set/user_set">
				<u-icon name="reload" color="#333333" :size="48"></u-icon>
			</navigator> -->
		</view>
    </view>
</template>
<script lang="ts" setup>
import { useCopy } from '@/hooks/useCopy'
import { useUserStore } from '@/stores/user'
const userStore = useUserStore()

const props = defineProps({
    content: {
        type: Object,
        default: () => ({})
    },
    styles: {
        type: Object,
        default: () => ({})
    },
    user: {
        type: Object,
        default: () => ({})
    },
    isLogin: {
        type: Boolean
    }
})
const { copy } = useCopy()
const navigateTo = (url: string) => {
    uni.navigateTo({
        url
    })
}
const logoutHandle = () => {
    uni.showModal({
        content: '是否退出登录？',
        confirmColor: '#4173FF',
        success: ({ cancel }) => {
            if (cancel) return
            userStore.logout()
            uni.redirectTo({ url: '/pages/login/login' })
        }
    })
}
</script>

<style lang="scss" scoped>
.user-info {
	position: relative;
    height: 156rpx;
    background-position: bottom;
    background-size: 100% auto;
	
	.user-btn {
		position: absolute;
		display: flex;
		top: 0;
		right: 40rpx;
	}
}
</style>
